package persistence;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;

public class CustomerTDG 
{

	//methods
	public static ArrayList<CustomerFascade> FindAll()
	{
		ArrayList<CustomerFascade> CustomersFascade = new ArrayList<CustomerFascade>(30);
		
		FileStorageRegistry.GetInstance().CheckFilesExist("src/customers.txt");
		
		File events = new File("src/customers.txt");

        try 
        {
        	BufferedReader reader = new BufferedReader(new FileReader(events));
        	String StaticIDCounter= reader.readLine();
        	CustomerFascade.setID_Counter(Integer.parseInt(StaticIDCounter));	        	
        	reader.readLine(); // skip '-' line
        	
        	String ID="";
        	String LastName="";
        	String FirstName="";
        	String Phone="";
        	
        	while(reader.ready())
        	{
        		ID = reader.readLine();
        		LastName = reader.readLine();
        		FirstName = reader.readLine();
        		Phone = reader.readLine();
        		
        		int IDint = Integer.parseInt(ID);
        	
        		CustomersFascade.add(new CustomerFascade(IDint,LastName,FirstName,Phone));

        		reader.readLine(); //skips past '-' of txt file
        	}

        	reader.close();
        } 
        
        catch (Exception e) 
        {
            System.err.println(e);
            System.exit(1);
        }
		
		return CustomersFascade;
	}
}
